//should added: appConfig.listeners = new HashMap();

Listener=function(){this.initialize.apply(this, arguments);}
Listener.prototype={
		
	initialize : function(){
		this.listenMaps= new HashMap();//Map<listenType,Map<number,listener>>
	},
	
	getListeners : function(listenType){
		return this.getListenMap(listenType);
	},
	
	getListenMap : function(listenType,create){
		var listenMap=this.listenMaps.get(listenType);
		if((!listenMap)&&create){
			listenMap = new HashMap();
			this.listenMaps.put(listenType,listenMap);
		}
		return listenMap;
	},
	
	addListener : function(listenType, fnHandle, fnKey){
		var listenMap=this.getListenMap(listenType,true);
		if(!fnKey){
			listenMap.put(listenMap.size()+1,fnHandle);
		}else{
			listenMap.put(fnKey,fnHandle);
		}
	},
	
	runListener : function(){
		var args = $A(arguments);
		var self = args.shift();
		var listenType = args.shift();
		var listenMap = this.getListenMap(listenType);
		if(!listenMap)return;
		var fnList = listenMap.values();
		if(!fnList)return;
		for(var i in fnList){
			try{
				//alert(listenType+" func: "+fnList[i]);
				//alert(listenType+" args:"+objectToString(args));
				fnList[i].apply(self,args);
			}catch(e){}
		}
	}

}

$listener = new Listener();

function getListener(listenType){
	return $listener.getListeners(listenType);
}

function addListener(listenType, fnHandle, fnKey){
	$listener.addListener(listenType, fnHandle, fnKey);
}

function runListener(listenType,args){
	$listener.runListener(this,listenType,args)
}
